home *** CD-ROM | disk | FTP | other *** search
- Path: canopus.cc.umanitoba.ca!natewild
- From: natewild@mbnet.mb.ca (Nathan T. Wild)
- Newsgroups: comp.lang.c++,comp.os.msdos.programmer
- Subject: Function Pointers In C++
- Date: Thu, 08 Feb 1996 13:25:54 -0500
- Organization: WankerNET - Digital TimeWasters Inc.
- Message-ID: <yAkGxc9nXE/T083yn@mbnet.mb.ca>
- NNTP-Posting-Host: access.mbnet.mb.ca
- Originator: natewild@access.mbnet.mb.ca
-
-
- I have a class which contains function pointers. The actual code for these
- functions is dynamically loaded from disk at run time. I seem to be having
- troubles setting these pointers??? I have done this before in C, but I
- guess C is a little more forgiving than C++ with respect to type checking.
- The declaration for my class is as follows (byte is a typedef to unsigned
- char):
-
-
- class MyClass {
- public:
- byte (far *Init)(void);
- byte (far *Reset)(void);
- byte (far *Enable)(void);
- byte (far *Disable)(void);
- byte (far *Close)(void);
- };
-
-
- In the constructor for this class, I call a function which reads the code
- into an allocated block and another function which returns a pointer to the
- functions. The driver files that are loaded from disk contain an offset
- (from the start of the driver code) to where each function exists within
- the driver. The following line is the critical line in the function
- "GetFunctionPtr" used to determine the address of each function.
-
-
- driverPtr is the pointer to the loaded driver's start.
- num is the effective offset for the desired function.
-
- return MK_FP(FP_SEG(driverPtr), peek(FP_SEG(driverPtr), (FP_OFF(driverPtr) + num)));
-
-
- In the constructor I am trying to execute code as follows:
-
- Init = GetFunctionPtr(1);
- Reset= GetFunctionPtr(2);
- ...
- etc.
-
- I get no end to the type error messages. GetFunctionPtr returns a void far *
- and I am not sure how to cast it to a "pointer to a function returning a
- byte"...
-
- Please give me a push in the right direction... RSVP via Email if
- possible, I co not carry this group "live"...
-
-
- |--------------------------------------------------------------------|
- | ooooO (``) (``) Ooooo | Nathan T. Wild |
- | ( ) ) ( ) ( ( ) | natewild@mbnet.mb.ca |
- | ) ( ( ) ( ) ) ( | ftp://ftp.mbnet.mb.ca/pub/natewild |
- | (__) ooooO Ooooo (__) | http://www.mbnet.mb.ca/~natewild |
- |--------------------------------------------------------------------|
-